package cn.com.dwr.modules.app.controller;

import cn.com.dwr.common.lang.Result;
import cn.com.dwr.entity.AppComment;
import cn.com.dwr.service.AppCommentService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

/**
 * 商品评论
 */
@RestController
@RequestMapping("/app/comment")
public class CommentController extends BaseController{

    @Resource
    AppCommentService appCommentService;

    /**
     * 商品评论列表
     * @param productId
     * @return
     */
    @GetMapping("/product")
    public Result product(long productId){
        return Result.success(appCommentService.pageByProductId(getPage(), productId));
    }

    /**
     * 查看订单未评论商品列表
     * @param status
     * @return
     */
    @GetMapping("/list")
    public Result list(Integer status){
        return Result.success(appCommentService.getPage(getPage(), status));
    }

    /**
     * 发表商品评论
     * @param pics
     * @param appComment
     * @return
     */
    @PostMapping("/post")
    public Result post(MultipartFile[] pics, @Validated AppComment appComment){
        appCommentService.post(pics, appComment);
        return Result.success();
    }
}
